#include <iostream>
#include <memory>
class Girl;
class Boy
{
public:
    Boy(){std::cout<<"男孩构造函数\n";}
    ~Boy(){std::cout<<"男孩析造函数\n+";}
    void SetGirlFriend(const std::shared_ptr<Girl>&ptr)
    {
        girlFriend  = ptr;
    }
private:
    std::weak_ptr<Girl> girlFriend; 
};

class Girl
{
public:
    Girl(){std::cout<<"女孩构造函数\n";}
    ~Girl(){std::cout<<"女孩析造函数\n";}
    void SetBoyFriend(const std::shared_ptr<Boy>&ptr)
    {
        boyFriend = ptr;
    }
private:
    std::weak_ptr<Boy> boyFriend; 
};

// void func(const std::shared_ptr)
int main()
{   
    //循环引用
    std::shared_ptr<Boy> b = std::make_shared<Boy>();
    std::shared_ptr<Girl> g = std::make_shared<Girl>();

    b->SetGirlFriend(g);
    g->SetBoyFriend(b);
    //weak_ptr 弱指针 shareed_ptr
    //weak_ptr不会使引用计数器加1 
    //时机：引入外部共享指针使用弱指针

    //谁申请 谁释放
    return 0;
}